﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace BLL
{
  public   class 当月进仓报表
    {
        public static DataTable CreateReport(DateTime date )
        {
            return Connect.CreatConnect().Query($"select day(rq) as '日期', sum(TotalMishu) as '米数' from danjutable where year(rq)={date.Year } and month(rq)={date.Month } and djlx='{DanjuLeiXing.入库单}' group by day(rq) order by 日期");
            // List<DanjuTable> dt = DanjuTableService.GetDanjuTablelst(x => x.djlx == DanjuLeiXing.入库单 && x.rq >= date.Date && x.rq < date.Date.AddMonths(1));
            // DataTable resdt = new DataTable();
            // resdt.Columns.Add("日期", typeof(DateTime));
            // resdt.Columns.Add("米数", typeof(decimal));
            //for(int i=0;i<date.AddMonths(1).AddDays(-1).Day ;i++)
            // {
            //     resdt.Rows.Add();
            //     resdt.Rows[i]["日期"] = date.AddDays(i);
            //     resdt.Rows[i]["米数"]=  dt.Where(x => x.rq >= date.AddDays(i) && x.rq <= date .AddDays(i + 1)).ToList ().Sum (x=>x.TotalMishu  );
            // }
            // return resdt;
        }
        public static DataTable CreateCustomerReport(DateTime date)
        {
            return Connect.CreatConnect().Query($"select ksmc,SUM(TotalMishu) as summishu  from DanjuTable  where year(rq)= {date.Year}  and Month(rq)= {date.Month} and day(rq)={date.Day } and djlx ='生产入库单' group by ksmc ");
        }
        public static DataTable CreateCustomerDetailReport(DateTime date)
        {
            return Connect.CreatConnect().Query($"select t0.ksmc,SUM(t1.chengpingmishu) as summishu,t1.pingming  from DanjuTable t0 inner join danjumingxitable t1 on " +
                $"t0.dh=t1.danhao   where year(t0.rq)='{date.Year  }' and month(t0.rq)='{date.Month }' and day(t0.rq)='{date.Day}' and t0.djlx ='生产入库单' group by t0.ksmc,t1.pingming ");
        }
    }
}
